<?php

class update_migration {
	public function install( $file ) {
		$this->apply( $file, 'install' );
	}

	public function remove( $file ) {
		$this->apply( $file, 'remove' );
	}

	private function apply( $file, $type ) {
		require 'migration/'.$file;
		if( $type == 'remove' ) remove(); else install();
		db()->insert('update_migration', array( 'id' => $file ));
	}

	public function create( $file ) {
		file_put_contents( 'migration/'.date('Ymd-Hi-').$file.'.php',
			"<?php\n\nfunction install() {\n\tdb()->query(\"\");\n}\n\nfunction remove() {\n\tdb()->query(\"\");\n}\n" );
	}
}
